count frequencies of all elements in array